const async = require('async')
const Constant = require("../constant/constant")
const expotObj = {
    clone,
    checkParams,
    autoFn
}
module.exports = expotObj
function clone(obj){
    return JSON.parse(JSON.stringify(obj))
}
function checkParams (params, checkArr, cb) {
    let flag = true;
    checkArr.forEach(v => {
      if (!params[v]) {
        flag = false;
      }
    });
    if (flag) {
      cb(null);
    }else{
      cb(Constant.LACK);
    }

  }
  function autoFn(tasks, res, resObj) {
    async.auto(tasks, function (err) {
        if (!!err) {
            console.log(JSON.stringify(err));
            res.json({
                code: err.code || Constant.DEFAULT_ERROR.code,
                msg: err.msg || JSON.stringify(err)
            });
        } else {
            res.json(resObj)
        }
    })
}